import random
import string

def num_single():
    return random.choice('1234567')

def num_multiple():
    num_choose=''
    for i in range(3):
        num_choose += num_single()
    return num_choose

stu_choose = [num_multiple() for i in range(10)] #随机生成学生选课序号
num_effective = len(stu_choose) #有效人数
name_sub= dict(zip(range(1,8),('物理化学生物政治历史地理技术'[i:i+2] for i in range(0,14,2)))) #学科序号表
count_sub = dict.fromkeys(range(1,8), 0) #每门课有效被选次数
percent_sub = [] #每门课选课率

#统计每门课有效被选次数及有效人数
for i in stu_choose:
    j = 0
    while j != len(i):
        count_sub[int(i[j])] += 1
        if i[j] in i[j + 1:]:
            num_effective -= 1
            for z in range(j + 1):
                count_sub[int(i[z])] -= 1
            break
        j += 1

#计算每门课选课率
for i in range(1,8):
    percent_sub.append('{:.2%}'.format(count_sub[i] / num_effective))

#输出学生选课序号
print ('选课组合')
for i in stu_choose:
    print (i)

#输出学科编号
print ('{}  {}'.format('编号','学科'))
for key,value in name_sub.items():
    # print (str(key) + '---' + value)
    print ('{} --- {}'.format(str(key),value))

#输出编号学科选课率
print ('{}  {}     {}'.format('编号','学科','选课率'))
for i in sorted(enumerate(percent_sub), key = lambda x:x[1], reverse = True):
    print ('{} --- {} --- {}'.format(str(i[0]+1), name_sub[i[0]+1],i[1]))

